import { Nodes } from '@knno/dom';

export interface PopupResult {
	value: unknown;
	text: string;
}

export interface PopupHandler<T extends Nodes> {
	(this: T): Promise<PopupResult | null>;
}

export interface FormItem {
	disabled(): boolean;
	disabled(value: boolean): this;

	value(): unknown;
	value(value: unknown): this;

	text(): string;
	text(value: string): this;
}

export abstract class Container extends Nodes {
	protected abstract readonly box: Nodes;

	override append(...elem: (Text | Element | (Element | Text)[])[]): this {
		this.box.append(...elem);
		return this;
	}

	override appendAll(nodes: (Nodes | Text)[]): this {
		this.box.appendAll(nodes);
		return this;
	}

	override insert(...elem: (Text | Element | (Element | Text)[])[]): this {
		this.box.insert(...elem);
		return this;
	}

	override remove(...elem: (Element | Text | (Element | Text)[])[]): this {
		this.box.remove(...elem);
		return this;
	}

	override html(): string;
	override html(text: string): this;
	override html(text?: string): string | this {
		if (text === undefined) {
			return this.box.html();
		} else {
			this.box.html(text);
			return this;
		}
	}
}
